<template>
  <div class="content-display">
    <h2 v-if="content.title" class="content-title">{{ content.title }}</h2>
    
    <p v-if="content.txt" class="content-text">{{ content.txt }}</p>
    
    <div v-if="content.images && content.images.length" class="image-grid">
      <img 
        v-for="(image, index) in content.images" 
        :key="index" 
        :src="image" 
        :alt="'Image ' + (index + 1)"
        class="content-image"
      />
    </div>
    
    <div v-if="content.date" class="date-display">
      {{ formatDate(content.date) }}
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref } from 'vue';
import { get_index_recommend } from "@/api/community/main.js"
import { useRoute } from 'vue-router';
const route = useRoute();
let content = ref({})

const formatDate = (date) => {
  if (typeof date === 'string') {
    return date;
  }
  
  if (date instanceof Date) {
    return date.toLocaleDateString();
  }
  
  if (date.year && date.month && date.day) {
    return `${date.year}-${date.month.toString().padStart(2, '0')}-${date.day.toString().padStart(2, '0')}`;
  }
  
  return 'Invalid date';
};

onMounted(async () => { 
    content.value = await get_index_recommend(5, route.query.id)
})
</script>

<style scoped>
.content-display {
  max-width: 860px;
  margin: 40px auto;
  padding: 30px;
  border-radius: 16px;
  background-color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  font-family: 'Arial', sans-serif;
}

.content-title {
  font-size: 2rem;
  font-weight: bold;
  margin-bottom: 20px;
  color: #222;
  text-align: center;
  line-height: 1.4;
}

.content-text {
  font-size: 1.1rem;
  color: #555;
  line-height: 1.8;
  margin-bottom: 30px;
  text-align: justify;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 20px;
  margin: 20px 0;
}

.content-image {
  width: 100%;
  height: auto;
  border-radius: 12px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.content-image:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.date-display {
  font-size: 0.95rem;
  color: #888;
  text-align: center;
  margin-top: 20px;
}
</style>